
<html lang='en'>
<head>
<title>smeoa</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<?php
echo 'aaaaa啊';
// phpinfo();

$mysqli=new mysqli('127.0.0.1','root','root','php');  
/* check connection */  
// 编码转化为 utf8
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
    printf("Current character set: %s\n", $mysqli->character_set_name());
}

if (mysqli_connect_errno()) {
    // 诊断连接错误
    die("could not connect to the database.\n" . mysqli_connect_error());
}

//查询mysqli prepare --开始
 $selectName='title';
 echo "<br/>";
if ($stmt = $mysqli->prepare("select username,password from user where username = ?")) {
    $stmt->bind_param("s", $selectName);
    $stmt->execute();
    $stmt->bind_result($username, $password);
    while ($stmt->fetch()) {
        echo "Name: $username ,$password  \n<br/>";
    }
    $stmt->close();
} 

//mysqli 查询结束-----

$insertName="zhangsan_insert";
//添加记录开始-----
/* if ($insertStmt = $mysqli->prepare("insert into user(username, password) values(?, 18)")) {
    $insertStmt->bind_param("s", $insertName);
    $insertStmt->execute();
    echo $insertStmt->affected_rows . "\n";
    $insertStmt->close();
} */
//添加记录结束-----

//更新记录开始-----
/* if ($updateStmt = $mysqli->prepare("update user set password = 'abcv12看3' where username=?")) {
    $updateStmt->bind_param("s", $insertName);
    $updateStmt->execute();
    echo $updateStmt->affected_rows . "\n";
    $updateStmt->close();
} */
//更新结束----


//删除记录开始-----
/* $result = $mysqli->query("delete from user where username = 'zhangsan'");
echo $result . "\n";

$mysqli->close();//关闭连接
 //删除记录结束-----
 */
// $sql="select * from user";  
  
// $res=$mysqli->query($sql);  
// if (!$res) {  
//     printf("Error: %s\n", mysqli_error($res));  
//     exit();  
// }  
// print_r($res->fetch_row());
//   while($row=$res->fetch_row()){
//       echo $row['username'];
//   }
// mysqli_close($mysqli);  

?>

	<body>
	</body>
	</html>
